
<link rel="stylesheet" type="text/css" href="public/css/style.css" /><?php
require_once './model/works.php';
$md_works = new Works();
$id_work = $_GET['id'];

//Lay cong viec tuong ung voi id tren
$params = array(
    'listId_works' => $id_work
);
$work = $md_works->select($params);
?>
<div class="container">
    <?php include 'template/header.php'; ?>
    <form  method="post"      enctype="multipart/form-data">
        File name <input type="text" name="name" value="<?php echo $work[0]["name"]; ?>"><br>
        File <input type="file" name="file" id="file"><br>
        <input type="submit" name="submit" value="submit">
    </form>
</div>
<?php
if (isset($_POST['submit'])){
    if ($_FILES["file"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br>";
    } else {
        if (file_exists("./public/Images/" . $_FILES["file"]["name"])) {
            echo $_FILES["file"]["name"] . " already exists. " . "<br>";
        } else {
            $_FILES["file"]["name"] = time()."-".$_FILES["file"]['name'];
            move_uploaded_file($_FILES["file"]["tmp_name"], "./public/images/" . $_FILES["file"]["name"]);
            echo "Stored in: " . "./public/images/" . $_FILES["file"]["name"] . "<br>";
            $info = array(
                "id" => $_GET["id"],
                "name" => $_POST["name"],
                    //"img" => "./public/images/" . $_FILES["file"]["name"]
            );
            $md_works->update($info);
        }
    }
}
?>
